//
//  DASimilarBook.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/27.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DASimilarBook.h"
#import "UIImageView+WebCache.h"
#import "Utility.h"
#import "DAHeader.h"
#import "UIViewAdditions.h"

@interface DASimilarBook ()
@property (nonatomic, strong) UILabel *label;
@end
@implementation DASimilarBook



- (void)creatSimilarBookImageWithArray:(NSArray *)array{
    
    [self removeAllSubviews];
    
    if (array.count > 4) {
        for (int i = 0; i < 4; i++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((60 + 5) * i, 0, 60, 80)];
            imageView.tag = 1000 + i;
            
            [imageView sd_setImageWithURL:[NSURL URLWithString:array[i][@"bookImage"]]];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickIndexImage:)];
            imageView.userInteractionEnabled = YES;
            [imageView addGestureRecognizer:tap];
            
            [self addSubview:imageView];
        }
        
    }else if (array.count <= 4 && array.count > 0){
        for (int i = 0; i < array.count; i++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((60 + 5) * i, 0, 60, 80)];
            imageView.tag = 1000 + i;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickIndexImage:)];
            imageView.userInteractionEnabled = YES;
            [imageView addGestureRecognizer:tap];
            [imageView sd_setImageWithURL:[NSURL URLWithString:array[i][@"bookImage"]]];
            [self addSubview:imageView];
        }
    }
     else {
        NSString *similarBookStr = NSLocalizedString(@"NoSimilarBookAtPresent", nil);
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 240, 30)];
        label.text = similarBookStr;
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [UIColor colorWithHexString:bookNameColor];
         label.tag = 2000;
        [self addSubview:label];
    }
    

}
- (void)clickIndexImage:(UITapGestureRecognizer *)tap{
    NSLog(@"111");
    NSInteger index = tap.view.tag - 1000;
    [self.delegate similarBookClick:index];
    NSLog(@"%ld", index);
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
